package cn.com.guage.single.badmash;

/**
 * 恶汉模式 静态代码块方式
 * 
 * @author yangdechao
 *
 */
public class Singleton2 {

	private static Singleton2 instance;

	public Singleton2() {
	}

	static {
		if (instance == null) {

			instance = new Singleton2();
		}
	}

	public static Singleton2 getInstance() {
		return instance;
	}

	public void say() {
		System.out.println("say");
	}

	public static void main(String[] args) {
		Singleton2 instance1 = Singleton2.getInstance();
		System.out.println(instance1);
		instance1.say();
		Singleton2 instance2 = Singleton2.getInstance();
		System.out.println(instance2);
	}

}
